#ifndef OBJECTMODEL_H
#define OBJECTMODEL_H

#include <QAbstractListModel>

class ObjectModel : public QAbstractListModel
{
    Q_OBJECT
public:
    explicit ObjectModel(QObject *parent = nullptr);
    ObjectModel(const QStringList &titles,QObject *parent = nullptr);
    ~ObjectModel();

    // ListModel implementations
    Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    Q_INVOKABLE int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    Qt::ItemFlags flags(const QModelIndex &index) const override;
    Q_INVOKABLE QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
    Q_INVOKABLE QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;

    // other
    Q_INVOKABLE bool insert(int row, QObject *item);
    Q_INVOKABLE void append(QObject *object);
    Q_INVOKABLE void clear();
    Q_INVOKABLE QObject *item(int row) const;
    Q_INVOKABLE bool removeItem(QObject *object);
    Q_INVOKABLE void notifyItemChanged(const QObject* item);

signals:
    void itemRemoved(int row);

private:
    QObjectList items;
    QStringList headers;

private slots:
    void onPropChanged();
};

#endif // OBJECTMODEL_H
